package com.horus.entities.dto.user;

import org.jasypt.util.password.PasswordEncryptor;
import org.jasypt.util.password.StrongPasswordEncryptor;

public class PasswordDigestJasyptImpl implements PasswordDigest {

	private String encryptedPassword;
	private String seed;	
	private PasswordEncryptor passwordEncryptor;

	public PasswordDigestJasyptImpl(){
		passwordEncryptor = new StrongPasswordEncryptor();
		seed = "m7b3R+5blt8rWF4ekzIWhcU1qpXJFz6GtXyev9/b58AGrE0T239MIYWbUwwMY6ew"; //TODO: Create Seed, use DB algorithm ?? use secret passphrase??
	}

	@Override
	public void encryptPassword(String password) {

		encryptedPassword = passwordEncryptor.encryptPassword(seed + password);
	}

	@Override
	public boolean validatePassword(String password) {

		return passwordEncryptor.checkPassword(seed + password,	encryptedPassword);
	}

	@Override
	public void setEncryptedPassword(String encryptedPassword) {
		
		this.encryptedPassword = encryptedPassword;
	}
	
	@Override
	public String getEncryptedPassword(){
		
		return encryptedPassword;
	}

}
